package com.ophiux.cs.infrastructure.compoment.basedata.mybatis;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

public class EnterprisePage  implements Serializable
{
	private static final long serialVersionUID = -7846965154924905005L;
	  private int pageSum = 1;
	  private int pageCurrent = 1;
	  private int rowSum;
	  private int pageRows = 10;
	  private int rowsCurrent;
	  private int pageFrom = 1;
	  private int pageTo = 1;
	  private int pageGroupBy = 10;
	  private List rowDatas;
	  private List data;

	  public List getData() {
		  
		return this.rowDatas;
	}

	public EnterprisePage()
	  {
	  }

	  public EnterprisePage(Map<String, Object> parameter)
	  {
	    if (parameter.containsKey("pageRows")) {
	      String pageRows = (String)parameter.get("pageRows");
	      if (!"".equals(pageRows)) {
	        setPageRows(Integer.parseInt(pageRows));
	      }
	    }
	    if (parameter.containsKey("pageCurrent")) {
	      String pageCurrent = (String)parameter.get("pageCurrent");
	      if (!"".equals(pageCurrent)) {
	        setPageCurrent(Integer.parseInt(pageCurrent));
	      }
	    }
	    if (parameter.containsKey("rowSum")) {
	      String rowSum = (String)parameter.get("rowSum");
	      if (!"".equals(rowSum)) {
	        setRowSum(Integer.parseInt(rowSum));
	      }
	    }
	    if (parameter.containsKey("pageGroupBy")) {
	      String pageGroupBy = (String)parameter.get("pageGroupBy");
	      if (!"".equals(pageGroupBy))
	        setPageGroupBy(Integer.parseInt("pageGroupBy"));
	    }
	  }

	  public void setRowSum(int rowSum)
	  {
	    this.rowSum = rowSum;
	    if (rowSum != 0) {
	      if (this.pageRows == 0) {
	        this.pageSum = 1;
	      } else {
	        this.pageSum = (rowSum % this.pageRows == 0 ? rowSum / this.pageRows : rowSum / this.pageRows + 1);

	        if (this.pageCurrent < 1)
	          this.pageCurrent = 1;
	        else if (this.pageCurrent > this.pageSum)
	          this.pageCurrent = this.pageSum;
	      }
	    }
	    else {
	      this.pageSum = 1;
	      this.pageCurrent = 1;
	    }
	    if (this.pageRows == 0) {
	      this.rowsCurrent = rowSum;
	    }
	    else if (this.pageCurrent >= this.pageSum) {
	      this.rowsCurrent = (rowSum % this.pageRows == 0 ? this.pageRows : rowSum % this.pageRows);
	    }
	    else {
	      this.rowsCurrent = this.pageRows;
	    }

	    if (this.pageCurrent % this.pageGroupBy == 0)
	      this.pageFrom = (this.pageCurrent - this.pageGroupBy + 1);
	    else {
	      this.pageFrom = (this.pageCurrent - this.pageCurrent % this.pageGroupBy + 1);
	    }
	    if (this.pageFrom < 1) {
	      this.pageFrom = 1;
	    }
	    if (this.pageFrom + this.pageGroupBy - 1 > this.pageSum)
	      this.pageTo = this.pageSum;
	    else
	      this.pageTo = (this.pageFrom + this.pageGroupBy - 1);
	  }

	  public void setPageRows(int pageRows)
	  {
	    if (pageRows < 0) {
	      return;
	    }
	    this.pageRows = pageRows;
	  }

	  public int getPageSum() {
	    return this.pageSum;
	  }

	  public void setPageSum(int pageSum) {
	    this.pageSum = pageSum;
	  }

	  public int getPageCurrent() {
	    return this.pageCurrent;
	  }

	  public void setPageCurrent(int pageCurrent) {
	    this.pageCurrent = pageCurrent;
	  }

	  public int getRowsCurrent() {
	    return this.rowsCurrent;
	  }

	  public void setRowsCurrent(int rowsCurrent) {
	    this.rowsCurrent = rowsCurrent;
	  }

	  public List getRowDatas()
	  {
	    return this.rowDatas;
	  }

	  public void setRowDatas(List rowDatas)
	  {
	    this.rowDatas = rowDatas;
	  }

	  public int getRowSum() {
	    return this.rowSum;
	  }

	  public int getPageRows() {
	    return this.pageRows;
	  }

	  public int getPageFrom() {
	    return this.pageFrom;
	  }

	  public void setPageFrom(int pageFrom) {
	    this.pageFrom = pageFrom;
	  }

	  public int getPageTo() {
	    return this.pageTo;
	  }

	  public void setPageTo(int pageTo) {
	    this.pageTo = pageTo;
	  }

	  public int getPageGroupBy() {
	    return this.pageGroupBy;
	  }

	  public void setPageGroupBy(int pageGroupBy) {
	    this.pageGroupBy = pageGroupBy;
	  }

}
